
#!/bin/bash
hostname=`hostname -f | cut -d '.' -f1`
metrics=""
for line in `df |awk 'NR>1{print $NF "=" int($(NF-1))}'`
do
disk_name=`echo $line|awk -F'=' '{print $1}'`
disk_usage=`echo $line|awk -F'=' '{print $2}'`
metrics="$metrics\ndisk_usage{instance=\"$hostname\",job=\"disk\",disk_name=\"$disk_name\"} $disk_usage"
done
echo -e "# A histogram, which has a pretty complex representation in the text \
format:\n# HELP http_request_duration_seconds A histogram of the request \ 
duration.\n# TYPE http_request_duration_seconds histogram\n$metrics" | curl --data-binary @- http://192.168.68.146:9091/metrics/job/pushgateway/instance/$hostname

# 编辑root用户级别计划任务配置文件，命令行执行crontab -e命令
# * * * * * /bin/bash /app/shell/disk_usage_metris.sh